package com.study.controller;

import com.study.common.enums.PrintTypeEnum;
import com.study.strategy.PrintTemplateStrategyFactory;
import lombok.extern.slf4j.Slf4j;
import net.sf.jasperreports.engine.JRException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 打印模板
 * @author hw
 * @date 2022/11/2 11:10:20
 */
@Slf4j
@RestController
@RequestMapping("/print")
public class PrintTemplateController {

    //http://localhost:8887/study/print/printTemplate?applyId=d6c1cf90380111ea834acb889ef8e7da&printType=SLGZS
    @RequestMapping({"/printTemplate","/api/printTemplate"})
    public void printTemplate(@RequestParam("applyId") String applyId, @RequestParam("printType") String printType, HttpServletRequest req, HttpServletResponse res) throws IOException, JRException, SQLException {
        try {
            PrintTypeEnum printTypeEnum = PrintTypeEnum.valueOf(printType);
            PrintTemplateStrategyFactory.getHandler(printTypeEnum).printTemplate(applyId, req, res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
